import { IPSAppDEUILogic } from '../dataentity/ipsapp-deuilogic';
import { IPSAppDataEntity } from '../dataentity/ipsapp-data-entity';
import { IPSAppUILogic } from './ipsapp-uilogic';
import { IPSAppUILogicRefView } from './ipsapp-uilogic-ref-view';
import { PSSysViewLogicImpl } from '../../res/pssys-view-logic-impl';

export class PSAppUILogicImpl extends PSSysViewLogicImpl implements IPSAppUILogic {
  get codeName(): string {
    return this.M.codeName;
  }

  get dynaModelFilePath(): string {
    return this.M.dynaModelFilePath;
  }

  protected psappdeuilogic: IPSAppDEUILogic | null = null;

  getPSAppDEUILogic(): IPSAppDEUILogic | null {
    if (this.psappdeuilogic != null) return this.psappdeuilogic;
    const value = this.M.getPSAppDEUILogic;
    if (value == null) {
      return null;
    }
    const ipsappdataentity = this.getPSAppDataEntity();
    if (ipsappdataentity != null) {
      this.psappdeuilogic = ipsappdataentity.findPSAppDEUILogic(value);
    }
    return this.psappdeuilogic;
  }

  get psAppDEUILogic(): IPSAppDEUILogic | null {
    return this.getPSAppDEUILogic();
  }

  getPSAppDEUILogicMust(): IPSAppDEUILogic {
    const value = this.getPSAppDEUILogic();
    if (value == null) {
      throw new Error('未指定应用实体界面逻辑对象');
    }
    return value;
  }

  protected psappdataentity: IPSAppDataEntity | null = null;

  getPSAppDataEntity(): IPSAppDataEntity | null {
    if (this.psappdataentity != null) return this.psappdataentity;
    const value = this.M.getPSAppDataEntity;
    if (value == null) {
      return null;
    }
    this.psappdataentity = this.getPSModel4('app.dataentity.IPSAppDataEntity', value, 'getPSAppDataEntity') as IPSAppDataEntity;
    return this.psappdataentity;
  }

  get psAppDataEntity(): IPSAppDataEntity | null {
    return this.getPSAppDataEntity();
  }

  getPSAppDataEntityMust(): IPSAppDataEntity {
    const value = this.getPSAppDataEntity();
    if (value == null) {
      throw new Error('未指定应用实体对象');
    }
    return value;
  }

  protected psappuilogicrefviews: IPSAppUILogicRefView[] | null = null;

  getPSAppUILogicRefViews(): IPSAppUILogicRefView[] | null {
    if (this.psappuilogicrefviews == null) {
      this.psappuilogicrefviews = this.fillChildListModel(this.M.getPSAppUILogicRefViews, 'app.logic.IPSAppUILogicRefView') as IPSAppUILogicRefView[];
    }
    return this.psappuilogicrefviews;
  }

  get psAppUILogicRefViews(): IPSAppUILogicRefView[] | null {
    return this.getPSAppUILogicRefViews();
  }

  findPSAppUILogicRefView(objKey: any): IPSAppUILogicRefView | null {
    return this.getPSModel5('app.logic.IPSAppUILogicRefView', this.getPSAppUILogicRefViews(), objKey) as IPSAppUILogicRefView;
  }

  get builtinLogic(): boolean {
    return this.M.builtinLogic != null ? this.M.builtinLogic : true;
  }

  get dynaInstModel(): boolean {
    return this.M.dynaInstModel != null ? this.M.dynaInstModel : false;
  }

  get cls(): string {
    return 'PSAppUILogicImpl';
  }

  instanceof(cls: string): boolean {
    if (cls == 'app.logic.IPSAppUILogic') return true;
    return super.instanceof(cls);
  }
}
